import * as THREE from "three";
import gsap from "gsap";
import vertex from "@/shader/lightWall/vertex.glsl";
import fragment from "@/shader/lightWall/fragment.glsl";

export default class LightWall {
    constructor(radius = 4, length = 2, position = { x: 0, z: 0 }) {
        this.geometry = new THREE.CylinderGeometry(radius, radius, 1, 35, 1, true)
        this.material = new THREE.ShaderMaterial({
            vertexShader: vertex,
            fragmentShader: fragment,
            transparent: true,
            side: THREE.DoubleSide,
        })
        this.mesh = new THREE.Mesh(this.geometry, this.material);
        this.mesh.position.set(position.x, 0, position.z);

        this.mesh.geometry.computeBoundingBox();
        let {min,max} = this.mesh.geometry.boundingBox;
        let uHeight = max.y - min.y;
    
        this.material.uniforms.uTopColor = {
            value:new THREE.Color("#ff0016")
        }
        this.material.uniforms.uHeight = {
            value:uHeight
        }

        // lightWall动画
        gsap.to(this.mesh.scale, {
            x: length,
            z: length,
            duration: 1,
            repeat: -1,
            yoyo: true
        })
    }
    remove() {
        this.mesh.remove();
        this.mesh.removeFromParent();
        this.mesh.geometry.dispose();
        this.mesh.material.dispose();
    }
}